//
//  UserInfoCell.swift
//  LiteAccount
//
//  Created by 刘伟 on 2017/5/14.
//  Copyright © 2017年 刘伟. All rights reserved.
//

import UIKit

class UserInfoCell: UITableViewCell {
    
    var data: [String]? {
        didSet {
            if let currentData = data {
                if currentData.count == 2 {
                    iconView.image = UIImage(named: currentData[0])?.imageWithColor(tintColor: UIColor.la_app)
                    titleLabel.text = currentData[1]
                }
            }
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        prepareUI()
        layoutUI()
    }
    
    fileprivate func prepareUI() {
        self.backgroundColor = .white
        self.selectionStyle = .none
        self.contentView.addSubview(iconView)
        self.contentView.addSubview(titleLabel)
        self.contentView.addSubview(detailLabel)
    }
    
    fileprivate func layoutUI() {
        iconView.snp.makeConstraints { (make) in
            make.top.left.equalTo(10)
            make.centerY.equalToSuperview()
            make.width.equalTo(iconView.snp.height)
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(iconView.snp.right).offset(10)
        }
        
        detailLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(-5)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: 视图控件
    fileprivate lazy var iconView: UIImageView = {
        let object = UIImageView()
        object.image = UIImage(named: "setting")
        object.contentMode = .scaleAspectFit
        object.clipsToBounds = true
        return object
    }()
    
    fileprivate lazy var titleLabel: UILabel = {
        let object = UILabel()
        object.textAlignment = .left
        object.textColor = UIColor.black
        object.font = UIFont.la_Font(ofSize: 15)
        object.text = "我的设置"
        return object
    }()
    
    fileprivate lazy var detailLabel: UILabel = {
        let object = UILabel()
        object.textAlignment = .left
        object.textColor = UIColor.la_gray
        object.font = UIFont.la_Font(ofSize: 12)
        object.text = ""
        return object
    }()

}
